package cn.tedu.minirice.controller;


import cn.tedu.minirice.constant.State;
import cn.tedu.minirice.entity.User;
import cn.tedu.minirice.service.UserService;
import cn.tedu.minirice.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@Api(value="提供商家登录注册，以及注销的接口", tags="商家管理")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation("商家登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "username", value = "用户登陆账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "password", value = "用户登陆密码", required = false, defaultValue = "111111")
    }
    )
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public ResultVO login(@RequestParam("username") String username,
                          @RequestParam(value = "password", defaultValue = "666666") String password){
        return userService.checkLogin(username, password);
    }

    @ApiOperation("商家注册接口")
    @ApiImplicitParam(name = "商家信息", value = "", required = true)
    @RequestMapping(value = "/regist", method = RequestMethod.POST)
    public ResultVO regist(User user){
        System.out.println(user);
        return new ResultVO(State.OK, "注册成功", null);
    }


}
